import {
	createRouter,
	createWebHistory
} from 'vue-router'

import Routermap from './router.js'

import { markRaw } from 'vue'

import Layout from '../views/Layout/Layout.vue'

/**
 * 避免浪费性能
 * 不会转为 proxy 对象，返回本身对象
 * 不是响应式对象
 * , roles: [374]
 */
const Layouts = markRaw(Layout)

export const constantRouterMap = [{
		path: '/login',
		component: () => import('../views/Login/index.vue'),
		hidden: true
	},
	{
		path: '/',
		component: Layouts,
		redirect: 'index',
		meta: {
			title: '首页'
		},
		children: [{
			path: 'index',
			component: () => import('../views/Home/index.vue'),
			name: 'index',
			meta: {
				title: '首页',
				icon: 'icon-51'
			}
		}]
	},
	{
		path: '/404',
		component: () => import('../views/Error/404.vue'),
		hidden: true
	},
	{
		path: '/401',
		component: () => import('../views/Error/401.vue'),
		hidden: true
	}
]

const Router = createRouter({
	history: createWebHistory(),
	scrollBehavior: () => ({
		top: 0
	}),
	routes: constantRouterMap
})

export default Router

export const asyncRouterMap = [
	...Routermap,
	{
		path: '/:pathMatch(.*)*',
		redirect: '/404',
		hidden: true
	}
]
